#pragma once

#include <list>

using namespace std;

#define AUTO_SIZE unsigned long size(){return sizeof(*this);}

class EngineObject
{
public:
	inline unsigned long AddRef()
	{
		return ++this->refCount;
	}
	inline void Release()
	{
		if (--refCount <= 0)
		{
			liveObjects.remove(this);
			deadObjects.push_back(this);
		}
	}
	static void CollectGarbage();
	static void CollectRemainingObjects(bool emitWarnings = false);
	virtual unsigned long size() = 0;
protected:
	EngineObject(void);
	virtual ~EngineObject(void);
private:
	static list<EngineObject*> liveObjects;
	static list<EngineObject*> deadObjects;
	unsigned long refCount;
};
